package com.one.rope.mvp.web.common.jwt;

import org.apache.commons.lang.ArrayUtils;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;

/**
 * @author Weijian.liu
 * @desc Cookies工具类
 * @date 2018/12/12
 */
public class CookieUtils {

  /**
   * 查找Cookie
   */
  public static Cookie getCookie(String name, HttpServletRequest request) {
    Cookie[] cookies = request.getCookies();
    if (ArrayUtils.isEmpty(cookies)) {
      return null;
    }
    Cookie cookie = null;
    for (Cookie item : cookies) {
      if (item.getName().equals(name)) {
        cookie = item;
      }
    }
    return cookie;
  }
}
